package homeworks.cjt2009.homework1.tsetso.solution;

import java.io.File;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;

public class TestClass {

	/**
	 * @param args
	 */

	private static final String PATH_FILES = "E:\\Java\\java_edu\\"
			+ "eclipse-workspace\\private-java-course\\src\\edu\\java\\"
			+ "javaCourseFMI\\homeworks\\cjt2009\\homework1\\";

	private static Room room1 = new Room(3, 2, 25.6f);
	private static Room room2 = new Room(6, 1, 39.5f);
	private static Room room3 = new Room(19, 4, 47);
	private static Room room4 = new Room(12, 3, 55.9f);

	private static Room room5 = new Room(17, 11, 43.6f);
	private static Room room6 = new Room(10, 32, 89.4f);

	private static Collection<Room> rooms = new HashSet<Room>();
	private static HashMap<Room, Collection<Guest>> roomGuests = new HashMap<Room, Collection<Guest>>();
	static {
		rooms.add(room1);
		rooms.add(room2);
		rooms.add(room3);
		rooms.add(room4);
	}

	private static HashSet<Guest> room1Guests = new HashSet<Guest>();
	private static HashSet<Guest> room2Guests = new HashSet<Guest>();
	private static HashSet<Guest> room3Guests = new HashSet<Guest>();
	private static HashSet<Guest> room4Guests = new HashSet<Guest>();

	private static Guest guest1 = new Guest("Ivan", "ivan@abv.bg");
	private static Guest guest2 = new Guest("Petar", "p@gmail.bg");
	private static Guest guest3 = new Guest("Milen", "mil@mail.bg");
	private static Guest guest4 = new Guest("Georgi", "geor@abv.bg");
	private static Guest guest5 = new Guest("John", "john@abv.bg");
	private static Guest guest6 = new Guest("Eve", "eve@abv.bg");
	private static Guest guest7 = new Guest("Susan", "sus@mail.bg");

	private static Guest guest8 = new Guest("Boyan", "boy@mail.bg");
	private static Guest guest9 = new Guest("Filip", "fil@mail.bg");

	static {
		room1Guests.add(guest1);
		room1Guests.add(guest2);
		room2Guests.add(guest3);
		room3Guests.add(guest4);
		room3Guests.add(guest5);
		room4Guests.add(guest6);
		room4Guests.add(guest7);
	}

	static {
		roomGuests.put(room1, room1Guests);
		roomGuests.put(room2, room2Guests);
		roomGuests.put(room3, room3Guests);
		roomGuests.put(room4, room4Guests);
	}

	public static void main(String[] args) {

		// testRoomClass();

		// testGuest();

		// testStringClass();

		// testLoadAndStoreFilesData();

		// testSortRoomsMethod();

		// generateRoomGuestMap();

		// testPopulateRoomsMethod();

		// testgetAvailableRoomsMethod();

		// testToStringGuestsMethod();

		// testGetGuestsInRoomMethod();

		// testGetRoomMethod();

		 testRentARoomMethod();

//		testMyHotelHashMapConstructor();

	}

	public static void testMyHotelHashMapConstructor() {
		roomGuests.put(room5, new HashSet<Guest>());
		roomGuests.put(room6, new HashSet<Guest>());
		
		MyHotel mh = new MyHotel(roomGuests);
		System.out.println(mh.getRooms());
		System.out.println("\n----------\n");
		System.out.println(mh);
	}

	public static void testRentARoomMethod() {
		roomGuests.put(room5, new HashSet<Guest>());
		roomGuests.put(room6, new HashSet<Guest>());

		// Room room10 = new Room(46, 3, 43.6f);
		MyHotel mh = new MyHotel(roomGuests);
		System.out.println(mh);

		Collection<Guest> guests = new HashSet<Guest>();
		guests.add(guest8);
		guests.add(guest9);

		try {
			Room rentedRoom = mh.rentARoom(guests);
			System.out.println("Rented room -->" + rentedRoom);
		} catch (NoAvailableRoomException e) {
			System.out.println("Exception: NoAvailableRoom");
		}

		System.out.println("----- Hotel Status After Renting a Room: --------");
		System.out.println(mh);
	}

	public static void testGetRoomMethod() {
		MyHotel mh = new MyHotel(roomGuests);

		Guest guest = null;
		// guest= guest1; // guest1 --> room1 --> roomNumber= 3
		// guest= guest5; // guest5 --> room3 --> roomNumber= 19
		guest = guest8; // nowhere
		System.out.println("Room number: " + mh.getRoom(guest));
	}

	public static void testToStringGuestsMethod() {
		Collection<Guest> guests = new HashSet<Guest>();
		guests.add(guest1);
		guests.add(guest2);
		guests.add(guest3);
		guests.add(guest4);
		System.out.println(Guest.toStringGuests(guests));
	}

	public static void testGetGuestsInRoomMethod() {
		// room6 --> Room(10, 2, 89.4f);
		// room1 --> Room(3, 2, 25.6f);
		roomGuests.put(room6, new HashSet<Guest>());
		MyHotel mh = new MyHotel(roomGuests);
		System.out.println(mh);
		System.out.println("\n------------------------------\n");

		Collection<Guest> guests = null;
		// guests= mh.getGuestInRoom(50);
		// guests = mh.getGuestInRoom(room6.getNumber());
		guests = mh.getGuestInRoom(room1.getNumber());
		System.out.println(Guest.toStringGuests(guests));
	}

	public static void testgetAvailableRoomsMethod() {
		// roomGuests.put(room5, new HashSet<Guest>());
		// roomGuests.put(room6, new HashSet<Guest>());
		MyHotel mh = new MyHotel(roomGuests);
		System.out.println(mh);
		System.out.println("\n------------------------------\n");

		Collection<Room> availableRooms = mh.getAvailableRooms();
		System.out.println(Room.toStringRooms(availableRooms));

	}

	public static void testPopulateRoomsMethod() {
		MyHotel mh = new MyHotel(roomGuests);
		System.out.println("Hotel Rooms Status before:");
		System.out.println(mh);
		System.out.println(mh.toStringRooms());
		System.out.println("\n------------------------------\n");

		Collection<Room> newRooms = new HashSet<Room>();

		newRooms.add(room5);
		newRooms.add(room6);
		mh.populateRooms(newRooms);
		System.out.println("Hotel Rooms Status after:");
		System.out.println(mh);
		System.out.println(mh.toStringRooms());
	}

	public static void testLoadAndStoreFilesData() {
		MyHotel mh = new MyHotel();
		File fileInput = new File(PATH_FILES + "test_input.txt");
		File fileOutput = new File(PATH_FILES + "test_output.txt");

		mh.load(fileInput);
		// System.out.println(mh);
		mh.store(fileOutput);
	}

	public static void testStringClass() {
		// 01 test startsWith(prefix) method
		// String prefix = "a";
		// String lineText = "ablaba";
		// System.out.println("Start with correct prefix: "
		// + lineText.startsWith(prefix));

		// 02 test split() method + regex
		// String line = "ablaba kasa      ksdi 1223 fd     ;d ;";
		// String[] lineElems = line.split("[ ]+");
		// System.out.println(Arrays.toString(lineElems));
	}

	public static void testRoomClass() {

		// test toString()
		System.out.println("\n------------- test toString() ---------------\n");
		Room room1 = new Room(12, 2, 14.5f);
		System.out.println(room1);

		// test equals()
		System.out.println("\n-------------- test equals() ----------------\n");
		Room room2 = new Room(12, 2, 14.5f);
		Room room3 = new Room(12, 3, 21.5f);
		Room room4 = new Room(10, 1, 10f);

		System.out.println("room2.equals(room3)  -->" + room2.equals(room3));
		System.out.println("room2.equals(room4)  -->" + room2.equals(room4));
		// System.out.println("room2.equals(new Object())  -->"
		// + room2.equals(new Object()));

		// test hashCode()
		System.out.println("\n-------------- test hashCode() --------------\n");
		System.out.println("room2.hashCode()= " + room2.hashCode());
		System.out.println("room2.hashCode()= " + room4.hashCode());

	}

	public static void testGuest() {
		// test toString()
		System.out.println("\n------------- test toString() ---------------\n");
		Guest guest1 = new Guest("Petar Ivanov", "pi@abv.bg");
		System.out.println(guest1);

		// test equals()
		System.out.println("\n------------- test equals() -----------------\n");
		Guest guest2 = new Guest("Ivan Ivanov", "ii@abv.bg");
		Guest guest3 = new Guest("Lia Ivanova", "li@abv.bg");
		Guest guest4 = new Guest("Lia Ivanova", "alabala@abv.bg");
		System.out.println("guest2.equals(guest3) -->" + guest2.equals(guest3));
		System.out.println("guest3.equals(guest4) -->" + guest3.equals(guest4));
		// System.out.println("guest2.equals(new Object())  -->"
		// + guest2.equals(new Object()));

		// test hashcode()
		System.out.println("\n------------- test hashcode() ---------------\n");
		System.out.println(guest1);
		System.out.println("guest1.hashCode()= " + guest1.hashCode());
		System.out.println("guest1.getName().hashCode()= "
				+ guest1.getName().hashCode());

	}

}
